<template>
	<view class="all">
		<view class="top">
			<view class="head">
				<image class="top-image" :src="data[0].songPhoto"
					mode="widthFix" />
				<view class="textInfo">
					<view class="text">
						排行榜
					</view>
					<view class="time">
						{{time}}
					</view>
				</view>
			</view>
			<view class="zhongjian">
				<text class="zi" @tap="intoList">加入到播放列表({{data.length}})</text>
			</view>
		</view>
		<view>
			<view>
				<u-swipe-action>
					<u-swipe-action-item :options="options2"  v-for="(item,index) in data" @click="cli($event, index,item.songId)"
						:key="item.songId">
						<view class="swipe-action u-border-top u-border-bottom iten" >
							<block >
								<view class="scroll-item" @tap="toRadio(item.songId)">
									<text class="song-number">{{index+1}}</text>
									<view class="song-info">
										<view class="song-title">{{item.songName}}</view>
										<view class="song-desc">
											{{item.singerName}} - {{item.songIntroduce}}
										</view>
									</view>
									<view class="s">
										<u-icon name="arrow-leftward"></u-icon>
									</view>
								</view>
							</block>
						</view>
					</u-swipe-action-item>
				</u-swipe-action>
			</view>
		</view>
		<view style="height: 60rpx;"></view>
	</view>
</template>

<script>
	import {mapMutations} from 'vuex'
	export default {
		data() {
			return {
				options2: [{
					text: '下一首播放 ',
					style: {
						backgroundColor: '#3c9cff'
					}
				}, {
					text: "加入歌单",
					style: {
						backgroundColor: "#D9AFD9",
					}
				}],
				code: Number,
				data: [],
				time: "",
				songL:[]
			};
		},
		methods: {
			...mapMutations('song',['addSongList']),
			intoList(){
				for(let i =0;i<this.songL.length;i++){
					this.addSongList(this.songL[i])
				}
				uni.showToast({
					title: "加入成功",
					duration: 500,
					position: 'center',
				})
			},
			async getInfo() {
				const {
					data: res
				} = await uni.$http.get("/cart/host15")
				this.songL = res.data
				if (res.code != 200) {
					uni.showToast({
						title: "获取信息失败",
						duration: 1000,
						position: 'center',
						icon: 'error'
					})
				}
				this.code = res.code
				this.data = res.data
				let time = new Date()
				let nowTime = this.timestampToTime(time.toLocaleString('en-US', {
					hour12: false
				}).split(" "))
				this.time = nowTime
			},
			timestampToTime(times) {
				console.log(times);
				let month = times[1]
				let day = times[2]
				let tim = times[4]
				return  month + '-' + day + ' ' + tim
			},
			toRadio(id) {
				uni.navigateTo({
					url: "/pages/mus/mus?songId=" + id
				})
			},
			gotoSongListLike(songId){
				uni.getStorage({
					key:"token",
					success() {
						uni.navigateTo({
							url:"/subpkg/songListLike/songListLike?songId="+songId
						})
					},
					fail() {
						uni.showToast({
							duration:1000,
							icon:'error',
							title:'请先登录'
						})
					}
				})
				// console.log("like"+songId);
			},
			async nextListen(songId){
				const {data:res} = await uni.$http.get('/song/find',{
					songId:songId
				})
				console.log(res);
				this.addSongList(res)
				console.log(this.songlist)
			},
			cli(e,index,id){
				switch(e.index){
					case 1:
						this.gotoSongListLike(id)
						break
					case 0:
						this.nextListen(id)
						break
				}
			}
		},
		onLoad() {
			this.getInfo()
		}
	}
</script>

<style lang="scss">
	.top {
		background-color: #A9C9FF;
		background-image: linear-gradient(180deg, #A9C9FF 0%, #FFBBEC 54%, #f0f0f0 99%);
	}

	.textInfo {
		margin-left: 35rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		height: 130rpx;
	}

	.text {
		margin-left: 30rpx;
		font-family: 宋体;
		font-size: 50rpx;
		font-weight: bolder;
	}

	.time {
		color: #5c5c5c;
		margin-left: 16rpx;
	}

	.head {
		width: 100%;
		height: 340rpx;
		display: flex;
		margin-left: 80rpx;
		align-items: center;
	}

	.top-image {
		width: 250rpx;
		border-radius: 20rpx;
	}

	.head {
		height: 500rpx;
		height: 500rpx;

	}

	.zhongjian {
		padding: 10rpx 30rpx;
		border-top: 2rpx solid gray;
		border-bottom: 2rpx solid gray;

		.zi {
			font-size: 35rpx;
			font-weight: 600;
			margin: 20rpx 40rpx;
		}
	}

	.scroll-item {
		padding-top: 20rpx;
		display: flex;
		background-color: #f0f0f0;
		/* justify-content: space-around; */
	}

	.song-number {
		width: 80rpx;
		line-height: 100rpx;
		text-align: center;
		font-size: 45rpx;
		margin-left: 20rpx;
		font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
		color: rgba(100, 98, 98, 0.8);
	}

	.scroll-item .song-info {
		position: relative;
		flex: 1;
		max-width: 50%;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		margin-bottom: 3px;
	}

	.song-info .song-title {
		font-size: 36rpx;
		color: #111;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.song-info .song-desc {
		font-size: 28rpx;
		color: #5c5c5c;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}


	.song-info .song-desc .bgimg {
		width: 60rpx;
		margin-right: 5rpx;
	}

	.s {
		position: absolute;
		right: 60rpx;
		margin-top: 10px;
	}
</style>
